import java.util.HashMap;

public class Test10 {
    public int minNumberOfFrogs(String croakOfFrogs) {
        char[] arrFogs = croakOfFrogs.toCharArray();
        String s = "croak";
        int n = s.length();
        int[] times = new int[n];
        HashMap<Character,Integer> hash = new HashMap<>();
        for(int i = 0 ; i < n ; i++) hash.put(s.charAt(i) , i); // crock的字符和下标对应关系
        for(char c : arrFogs){
            int index = hash.get(c);
            if(index == 0){
                if(times[n -1] != 0) times[n-1]--;
                times[index]++;
            }else{
                if(times[index - 1] == 0) return -1;
                else {
                    times[index - 1]--;
                    times[index]++;
                }
            }
        }

        for(int i = 0 ; i < n - 1; i++){
            if(times[i] != 0) return -1;
        }

        return times[n-1];

    }
}
